﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using ListenMusic.Album_ServiceReference;
using System.ServiceModel;
using ListenMusic.Models.ViewModel;
namespace ListenMusic.Models.Reposistory.Public
{
    public class AlbumReposistory
    {
        AlbumServiceClient albumClient;
        SongReposistory _song;
        public AlbumReposistory()
        {
            albumClient = new AlbumServiceClient();
           

            //_song = new SongReposistory();
        }
        public List<View_BXH_Album> getBXH_Album()
        {
            try
            {
                View_BXH_Album[] bxh_Album = albumClient.getBXH_Album();
                return bxh_Album.ToList();
            }
            catch (FaultException e) { throw e; }
        }
        public List<Album> getAllAlbum()
        {
            try
            {
                Album[] album = albumClient.getAllAlbum();
                return album.ToList();
            }
            catch (FaultException e) { throw e; }
        }
        public Album getAlbum_byID(int albumid)
        {
            try
            {
                Album album = albumClient.getAlbum_byID(albumid);
                return album;
            }
            catch (FaultException e) { throw e; }
        }
        public List<Album> getAllAlbum_bySingerID(int singerid)
        {
            try
            {
                Album[] album = albumClient.getAllAlbum_bySingerID(singerid);
                return album.ToList();
            }
            catch (FaultException e) { throw e; }
        }
        public List<View8_Random_Album> get8Random_Album()
        {
            try
            {
                View8_Random_Album[] album = albumClient.get8Random_Album();
                return album.ToList();
            }
            catch (FaultException e) { throw e; }
        }
        public List<AlbumSinger> search_AlbumName(int start, int end,string albumName)
        {
            try
            {
                AlbumSinger[] album = albumClient.getAllAlbum_byAlbumName(albumName);
                return album.Skip(start).Take(end).ToList();
            }
            catch (FaultException e) { throw e; }
        }
        public int countAlbum_byAlbumName(string albumName)
        {
            return albumClient.getAllAlbum_byAlbumName(albumName).Count();
        }
        public List<AlbumSinger> get5New_Albun()
        {
            try
            {
                AlbumSinger[] album = albumClient.get5New_album();
                return album.ToList();
            }
            catch (FaultException e) { throw e; }
        }
        public List<AlbumSinger> getAllAlbum_byCategoryID(int start, int end,int categoryid)
        {
            try
            {
                AlbumSinger[] album = albumClient.getAlbum_byCategoryid(categoryid);
                return album.Skip(start).Take(end).ToList();
            }
            catch (FaultException e) { throw e; }
        }
        public int countAlbum_byCategoryID(int categoryid)
        {
            try
            {
                return albumClient.countAlbum_byCategoryid(categoryid);
            }
            catch (FaultException e) { throw e; }
        }
        public List<CountryAlbum> getRange_Album_byCountryid(int countryid)
        {
            try
            {
                CountryAlbum[] album = albumClient.getRangeAlbum_byCountryID(countryid);
                return album.ToList();
            }
            catch (FaultException e) { throw e; }
        }
        public bool updateCountView(int albumid)
        {
            try
            {
                return albumClient.updateCountView(albumid);
            }
            catch (FaultException e) { throw e; }
        }
        public List<AlbumSinger> getAllAlbumSinger_bySingerID(int singerid)
        {
            try
            {
                AlbumSinger[] als = albumClient.getAllAlbumSinger_bySingerID(singerid);
                return als.ToList();
            }
            catch (FaultException e) { throw e; }
        }
        public List<AlbumSinger> getAllAlbumSinger_bySingerName(int start, int end,string singerName)
        {
            try
            {
                AlbumSinger[] als = albumClient.getAllAlbumSinger_bySingerName(singerName);
                return als.Skip(start).Take(end).ToList();
            }
            catch (FaultException e) { throw e; }
        }
        public int countAlbumSinger_bySingerName(string singerName)
        {
            return albumClient.getAllAlbumSinger_bySingerName(singerName).Count();
        }
    }   
}